<?php declare(strict_types=1);
/**
 * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
 *
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

namespace OCA\DocumentServer\Document;


class DocumentFormat {
	const AVS_OFFICESTUDIO_FILE_UNKNOWN = 0x0000;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT = 0x0040;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0001;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0002;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0003;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0004;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0005;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0006;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0007;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_EPUB = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0008;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_FB2 = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0009;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_MOBI = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000a;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000b;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000c;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000d;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT_FLAT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000e;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_OTT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000f;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC_FLAT = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0010;
	const AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER = self::AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0011;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION = 0x0080;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0001;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0002;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0003;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0004;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0005;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0006;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0007;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0008;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP_FLAT = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0009;
	const AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP = self::AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x000a;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET = 0x0100;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0001;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0002;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0003;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0004;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0005;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0006;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0007;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0008;
	const AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS = self::AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0009;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM = 0x0200;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0001;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SWF = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0002;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0003;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_XPS = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0004;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0005;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0006;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR_MENU = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0007;
	const AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR_CANVAS = self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0008;
	const AVS_OFFICESTUDIO_FILE_IMAGE = 0x0400;
	const AVS_OFFICESTUDIO_FILE_IMAGE_JPG = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0001;
	const AVS_OFFICESTUDIO_FILE_IMAGE_TIFF = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0002;
	const AVS_OFFICESTUDIO_FILE_IMAGE_TGA = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0003;
	const AVS_OFFICESTUDIO_FILE_IMAGE_GIF = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0004;
	const AVS_OFFICESTUDIO_FILE_IMAGE_PNG = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0005;
	const AVS_OFFICESTUDIO_FILE_IMAGE_EMF = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0006;
	const AVS_OFFICESTUDIO_FILE_IMAGE_WMF = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0007;
	const AVS_OFFICESTUDIO_FILE_IMAGE_BMP = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0008;
	const AVS_OFFICESTUDIO_FILE_IMAGE_CR2 = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x0009;
	const AVS_OFFICESTUDIO_FILE_IMAGE_PCX = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x000a;
	const AVS_OFFICESTUDIO_FILE_IMAGE_RAS = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x000b;
	const AVS_OFFICESTUDIO_FILE_IMAGE_PSD = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x000c;
	const AVS_OFFICESTUDIO_FILE_IMAGE_ICO = self::AVS_OFFICESTUDIO_FILE_IMAGE + 0x000d;
	const AVS_OFFICESTUDIO_FILE_OTHER = 0x0800;
	const AVS_OFFICESTUDIO_FILE_OTHER_EXTRACT_IMAGE = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0001;
	const AVS_OFFICESTUDIO_FILE_OTHER_MS_OFFCRYPTO = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0002;
	const AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0003;
	const AVS_OFFICESTUDIO_FILE_OTHER_OLD_DOCUMENT = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0004;
	const AVS_OFFICESTUDIO_FILE_OTHER_OLD_PRESENTATION = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0005;
	const AVS_OFFICESTUDIO_FILE_OTHER_OLD_DRAWING = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0006;
	const AVS_OFFICESTUDIO_FILE_OTHER_TEAMLAB_INNER = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0007;
	const AVS_OFFICESTUDIO_FILE_OTHER_JSON = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0008; // Для mail-merge
	const AVS_OFFICESTUDIO_FILE_OTHER_PDFA = self::AVS_OFFICESTUDIO_FILE_OTHER + 0x0101;
	const AVS_OFFICESTUDIO_FILE_TEAMLAB = 0x1000;
	const AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY = self::AVS_OFFICESTUDIO_FILE_TEAMLAB + 0x0001;
	const AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY = self::AVS_OFFICESTUDIO_FILE_TEAMLAB + 0x0002;
	const AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY = self::AVS_OFFICESTUDIO_FILE_TEAMLAB + 0x0003;
	const AVS_OFFICESTUDIO_FILE_CANVAS = 0x2000;
	const AVS_OFFICESTUDIO_FILE_CANVAS_WORD = self::AVS_OFFICESTUDIO_FILE_CANVAS + 0x0001;
	const AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET = self::AVS_OFFICESTUDIO_FILE_CANVAS + 0x0002;
	const AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION = self::AVS_OFFICESTUDIO_FILE_CANVAS + 0x0003;

	public static function getFormatFromExtension(string $extension): int {
		switch (strtolower($extension)) {
			case 'docx':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX;
			case 'doc':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC;
			case 'odt':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT;
			case 'rtf':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF;
			case 'txt':
			case 'xml':
			case 'xslt':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_TXT;
			case 'htm':
			case 'html':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML;
			case 'mht':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_MHT;
			case 'epub':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_EPUB;
			case 'fb2':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_FB2;
			case 'mobi':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_MOBI;
			case 'docm':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM;
			case 'dotx':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX;
			case 'dotm':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTM;
			case 'fodt':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT_FLAT;
			case 'ott':
				return self::AVS_OFFICESTUDIO_FILE_DOCUMENT_OTT;

			case 'pptx':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX;
			case 'ppt':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_PPT;
			case 'odp':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP;
			case 'ppsx':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSX;
			case 'pptm':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTM;
			case 'ppsm':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_PPSM;
			case 'potx':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_POTX;
			case 'potm':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_POTM;
			case 'fodp':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_ODP_FLAT;
			case 'otp':
				return self::AVS_OFFICESTUDIO_FILE_PRESENTATION_OTP;

			case 'xlsx':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX;
			case 'xls':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLS;
			case 'ods':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS;
			case 'csv':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_CSV;
			case 'xlsm':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM;
			case 'xltx':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTX;
			case 'xltm':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM;
			case 'fods':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT;
			case 'ots':
				return self::AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS;

			case 'jpeg':
			case 'jpe':
			case 'jpg':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_JPG;
			case 'tif':
			case 'tiff':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_TIFF;
			case 'tga':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_TGA;
			case 'gif':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_GIF;
			case 'png':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_PNG;
			case 'emf':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_EMF;
			case 'wmf':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_WMF;
			case 'bmp':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_BMP;
			case 'cr2':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_CR2;
			case 'pcx':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_PCX;
			case 'ras':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_RAS;
			case 'psd':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_PSD;
			case 'ico':
				return self::AVS_OFFICESTUDIO_FILE_IMAGE_ICO;

			case 'pdf':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF;
			case 'swf':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SWF;
			case 'djvu':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_DJVU;
			case 'xps':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_XPS;
			case 'svg':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_SVG;
			case 'htmlr':
				return self::AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_HTMLR;
			case 'doct':
				return self::AVS_OFFICESTUDIO_FILE_TEAMLAB_DOCY;
			case 'xlst':
				return self::AVS_OFFICESTUDIO_FILE_TEAMLAB_XLSY;
			case 'pptt':
				return self::AVS_OFFICESTUDIO_FILE_TEAMLAB_PPTY;
			default:
				return self::AVS_OFFICESTUDIO_FILE_UNKNOWN;
		}
	}
}
